﻿
myApp.controller("RSSDetailCtrl", function ($scope, $post, $http, $resource, $routeParams, $restUrls, $rootScope, $location) {

    $scope.item_id = $routeParams.id;

    var getDetail = function () {
        $resource($restUrls["subscription"] + '&id=:id').get({ id: $scope.item_id }).$promise.then(function (data) {

            $scope.item = data.data;

            //微信分享
            wx.ready(function () {
                wx.onMenuShareTimeline({
                    title: 'test', // 分享标题
                    link: window.location.href, // 分享链接
                    imgUrl: '', // 分享图标
                    success: function () {
                        // 用户确认分享后执行的回调函数
                        $.post("http://yxp.shicifang.cc/api/index.php?route=account/wxshare/addRecord", { link: link });
                        $.post("http://yxp.shicifang.cc/api/index.php?route=account/reward/updateReward", { points: 1,description:'订阅文章分享赠送1积分' });
                    },
                    cancel: function () {
                        // 用户取消分享后执行的回调函数
                    }
                });
                wx.onMenuShareAppMessage({
                    title: 'test', // 分享标题
                    desc: '', // 分享描述
                    link:  window.location.href, // 分享链接
                    imgUrl: '', // 分享图标
                    type: '', // 分享类型,music、video或link，不填默认为link
                    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                    success: function () {
                        // 用户确认分享后执行的回调函数
                        $.post("http://yxp.shicifang.cc/api/index.php?route=account/wxshare/addRecord", { link: link });
                        $.post("http://yxp.shicifang.cc/api/index.php?route=account/reward/updateReward", { points: 1,description:'订阅文章分享赠送1积分' });
                    },
                    cancel: function () {
                        // 用户取消分享后执行的回调函数
                    }
                });
            })

        });
    }

    
    getDetail();

    $scope.show_popup = false;
    $scope.message = "";
    $scope.comment = function () {
        $scope.show_popup = true;
    }
    $scope.send_comment = function () {
       

        $post($restUrls["comment"],
          {
              post_id: $scope.item_id,
              message: $scope.message
          })
          .success(function (result) {
              $scope.message = "";
              $scope.show_popup = false;
              getDetail();
          }).error(function (data, status, headers, config) {
              $scope.show_popup = false;
          });

       
    }

    $scope.close_comment = function () {
        $scope.show_popup = false;
        $scope.message = "";
    }
});
